﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using POS.USBScanner;

namespace WPFTest
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        BarcodeScannerListener listener;

        public MainWindow()
        {
            InitializeComponent();
            this.ContentRendered += new EventHandler(MainWindow_ContentRendered);
        }

        void MainWindow_ContentRendered(object sender, EventArgs e)
        {
            listener = new BarcodeScannerListener();
            listener.BarcodeScanned += this.OnBarcodeScanned;
        }

        private void OnBarcodeScanned(object sender, EventArgs e)
        {
            var be = e as BarcodeScannedEventArgs;

            if (be != null)
            {
                string message;

                message = string.Format(
                    CultureInfo.CurrentCulture,
                    "You scanned {0} from device '{1}'.",
                    be.Barcode,
                    be.DeviceInfo.FriendlyName);

               =System.Diagnostics.Debug.WriteLine(message);
                MessageBox.Show(message);
            }
        }
    }
}
